var treeview = function() {
	return {
		init: function() {
			treeview.initTree();
			treeview.selectChange();
			treeview.fullIframe();
		},
		initTree:function() {
			
			$.ajax({
				url: ctx + '/factory/factoryArea/listFactoryTree/get.mvc',
				type: "post",
				dataType: 'json',
				data: {},
                async:false,
				success: function(response) {
					if (response.result == true) {
						$('#treeview').treeview({
							data: response.data, // data is not optional
							levels: 1,
					        //selectedBackColor: false,  
					        //selectedColor: '#337AB7',  
					        showCheckbox: false,//显示选择框
					        hierarchicalCheck:true,//层级联动选择
					        propagateCheckEvent:true, //层级联动
		        			//multiSelect: 1,//可以多选
					        onNodeSelected : function(event, data){
					        	//回调选中事件
					        	//更新页面和选择框
					        	var pkId=data.id;
					        	$(".configuration_title").text(data.text);
					        	$(".configuration_title").attr("title",data.text);
					        	//设置名称
					        	$.ajax({
									url: ctx + '/equipment/configuration/threed/listAllConfiguration/get.mvc',
									type: "post",
									dataType: 'json',
									data: {pkId:pkId},
					                async:false,
									success: function(response) {
										$(".configuration-select").empty();
										if (response.result == true) {
											//更新select
											for(var i=0;i<response.data.length;i++){
												$(".configuration-select").append("<option value='"+response.data[i].pkId+"'>"+response.data[i].name+"</option>")
											}
											//第一个组态信息为id
											fileKey=response.data[0].pkId;
											treeview.flushIframe();
										}
									},
									error: function(XMLHttpRequest, textStatus, errorThrown) {
										alert("系统错误");
									}
								});
					        	
					        }

						});
						
						setTimeout(function(){
							$('.list-group-item').each(function() {
								debugger;
								let _text = $(this).text();
								$(this).attr('title', _text);
							})
						},1500)
					}
				},
				error: function(XMLHttpRequest, textStatus, errorThrown) {
					alert("系统错误");
				}
			});



		},
        selectChange:function () {
		    $(".configuration-select").off("change").on("change",function(){
		    	var value = $('.configuration-select option:selected').val();
				fileKey=value;
				treeview.flushIframe();
		    });
        },
        flushIframe : function(){
        	$(".configuration-iframe").attr("src",scadaShowUrl+"?fileKey="+fileKey);
        },
        fullIframe: function(){
        	$(".configuration-full").on("click",function(){
        		if($(this).data("type")=="1"){
        			//非全屏加入全屏
        			$(this).text("正常显示");
        			$(".factory-right-container").addClass("full-screen");
        			$(this).data("type",2)
        		}else{
        			//全屏变非全屏
        			$(this).text("全屏显示");
        			$(".factory-right-container").removeClass("full-screen");
        			$(this).data("type",1)
        		}
        	})
        }
	};
}();

jQuery(document).ready(function() {
	
    treeview.init();
});

